package com.cloud.shopping.goods.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cloud.shopping.goods.model.Brand;
import com.cloud.shopping.goods.service.BrandService;
import com.cloud.shopping.tool.RespResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author John.zhang
 * @version Id: BrandController, v 1.0 2020/12/25 14:13 ZhiYong Exp $
 */

@Api(tags = "品牌模块")
@RestController
@RequestMapping(value = "/brand")
public class BrandController {

    @Resource
    private BrandService brandService;

    /**
     * 增加方法
     *
     * @param brand brand
     * @return
     */
    @ApiOperation("增加品牌信息")
    @ApiImplicitParam(name = "brand", value = "品牌信息")
    @PostMapping
    public RespResult add(@RequestBody Brand brand) {
        brandService.save(brand);
        return RespResult.ok();
    }

    /**
     * 修改方法
     *
     * @param brand brand
     * @return
     */
    @ApiOperation("修改品牌信息")
    @ApiImplicitParam(name = "brand", value = "品牌信息")
    @PutMapping
    public RespResult update(@RequestBody Brand brand) {
        brandService.updateById(brand);
        return RespResult.ok();
    }


    /**
     * 删除方法
     *
     * @param id id
     * @return
     */
    @ApiOperation("删除品牌信息")
    @ApiImplicitParam(name = "id", value = "品牌信息Id")
    @DeleteMapping("/{id}")
    public RespResult delete(@PathVariable(value = "id") String id) {
        brandService.removeById(id);
        return RespResult.ok();
    }

    /**
     * 条件查询
     *
     * @param brand brand
     * @return
     */
    @ApiOperation("品牌信息查询")
    @ApiImplicitParam(name = "brand", value = "品牌信息")
    @PostMapping(value = "/search")
    public RespResult queryList(@RequestBody Brand brand) {
        List<Brand> brands = brandService.queryList(brand);
        return RespResult.ok(brands);
    }


    /**
     * 条件分页查询
     *
     * @param page  page
     * @param size  size
     * @param brand brand
     * @return
     */
    @ApiOperation("品牌信息分页查询")
    @ApiImplicitParams({@ApiImplicitParam(name = "page", value = "页码")
            ,@ApiImplicitParam(name = "size", value = "页数")
            ,@ApiImplicitParam(name = "brand", value = "品牌信息")})
    @PostMapping(value = "/search/{page}/{size}")
    public RespResult queryPageList(
            @PathVariable(value = "page") Long page,
            @PathVariable(value = "size") Long size,
            @RequestBody Brand brand) {
        Page<Brand> pageInfo = brandService.queryPageList(brand, page, size);
        return RespResult.ok(pageInfo);
    }



}
